package simpleTaskDispatcher.model.tasks.impl;

import java.util.concurrent.Semaphore;

import simpleTaskDispatcher.model.tasks.ITaskAllowedAfterTaskQueueClose;


public class BarrierTask extends ContextFreeTask implements ITaskAllowedAfterTaskQueueClose {

	private final Semaphore workersWaitingForBarrier;
	
	private final Semaphore barrierFinished;
	
	private final int currentHaltedWorkers;
	
	public BarrierTask(Semaphore workersWaitingForBarrier, Semaphore barrierFinished, int currentHaltedWorkers) {
		super();
		this.workersWaitingForBarrier = workersWaitingForBarrier;
		this.barrierFinished = barrierFinished;
		this.currentHaltedWorkers = currentHaltedWorkers;
		this.setWorkValue(0);
	}
	
	public void execute() throws InterruptedException {
		workersWaitingForBarrier.acquire();
	}

	public int getCurrentHaltedWorkers() {
		return currentHaltedWorkers;
	}

	public Semaphore getWorkersWaitingForBarrier() {
		return workersWaitingForBarrier;
	}

	public Semaphore getBarrierFinished() {
		return barrierFinished;
	}

	@Override
	public String toString() {
		return super.toString();
	}

	
	
}
